﻿using AutoMapper;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.ProcessEgine.API.Applocations.Commands.FormTypeInfoCommand;
using B.S.ProcessEgine.Domain.Entities;
using B.S.ProcessEgine.ErrorCode;
using B.S.ProcessEgine.Infractructure.Interfaces;
using MediatR;

namespace B.S.ProcessEgine.API.Applocations.CommandHandlers.FormTypeInfoHandler
{
    public class UpdateFromTypeInfoHandler:IRequestHandler<UpdateFormTypeInfoCommand,ApiResult>
    {
        private readonly IFormTypeRepository formType;
        ILogger<UpdateFromTypeInfoHandler> logger;
        IMapper mapper;

        public UpdateFromTypeInfoHandler(IFormTypeRepository formType, ILogger<UpdateFromTypeInfoHandler> logger, IMapper mapper)
        {
            this.formType = formType;
            this.logger = logger;
            this.mapper = mapper;
        }
        /// <summary>
        /// 表单修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResult> Handle(UpdateFormTypeInfoCommand request, CancellationToken cancellationToken)
        {
            try
            {
                

                
                var res = await formType.UpdateAsync(request.data);


                return res > 0 ? ApiResult.Success(StateCodeEnum.Ok) : ApiResult.Fail("修改表单失败", StateCodeEnum.Ok);
            }
            catch (Exception ex)
            {
                logger.LogError("表单修改出错" + ex.Message);
                throw;
            }
        }
    }
}
